package com.wnxy.parking.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wnxy.parking.common.result.Result;
import com.wnxy.parking.entity.Parking;
import com.wnxy.parking.service.IParkingService;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Jet
 * @since 2023-08-19
 */
@RestController
@RequestMapping("/parking")
public class ParkingController {

    @Resource
    private IParkingService parkingService;

    /**
     * 列表
     */
    @GetMapping
    public Result<List<Parking>> findAll() {
        List<Parking> list = parkingService.list();
        return Result.ok(list);
    }

    /**
     * 分页列表
     * @param pageNum 当前页
     * @param pageSize 页大小
     * @return
     */
    @ApiImplicitParam(name = "map",dataTypeClass = Map.class, paramType = "body")
    @PostMapping("/page/{pageNum}/{pageSize}")
    public Result<IPage<Parking>> findPage(
            @PathVariable("pageNum")Integer pageNum,
            @PathVariable("pageSize")Integer pageSize,
            @RequestBody Map<String,String> map) {
        IPage<Parking> page = parkingService.findPage(pageNum,pageSize,map);
        return Result.ok(page);
    }

    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    public Result<Parking> findOne(@PathVariable Integer id) {
        return Result.ok(parkingService.getById(id));
    }

    /**
     * 添加或修改
     */
    @PostMapping
    public Result saveOrUpdate(@RequestBody Parking parking) {
        parkingService.saveOrUpdate(parking);
        return Result.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        parkingService.removeById(id);
        return Result.ok();
    }

    /**
     * 批量删除
     */
    @PostMapping("/del/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        parkingService.removeByIds(ids);
        return Result.ok();
    }

}

